package antoine.ear.generator.chords;

import java.util.ArrayList;
import java.util.List;

import antoine.ear.exo.Exo;
import antoine.ear.generator.ChordGenerator;
import antoine.ear.generator.NoteGenerator;
import antoine.ear.generator.sequences.Alt7SequenceGenerator;
import antoine.ear.generator.sequences.MixolydianSequenceGenerator;

public class Dom7Generator extends ChordGenerator {

	public Dom7Generator() {
		this.sequenceGenerator = new MixolydianSequenceGenerator();
	}

	public void reinit(){
		this.sequenceGenerator = new MixolydianSequenceGenerator();
	}
	
	public List generate(int note, int tick, int delay) {
		List res = new ArrayList();
		
		this.tonique = note;
		note += 48;
		
		/*res.add(createNoteOnEvent(note, tick));
		res.add(createMetaMessOnEvent(note, tick, Exo.ACTIVATENOTE));
		res.add(createMetaMessOnEvent(note, tick+delay, Exo.DESACTIVATENOTE));
		res.add(createNoteOnEvent(note+4, tick));
		res.add(createMetaMessOnEvent(note+4, tick, Exo.ACTIVATENOTE));
		res.add(createMetaMessOnEvent(note+4, tick+delay, Exo.DESACTIVATENOTE));
		res.add(createNoteOnEvent(note+7, tick));
		res.add(createMetaMessOnEvent(note+7, tick, Exo.ACTIVATENOTE));
		res.add(createMetaMessOnEvent(note+7, tick+delay, Exo.DESACTIVATENOTE));
		res.add(createNoteOnEvent(note+10, tick));
		res.add(createMetaMessOnEvent(note+10, tick, Exo.ACTIVATENOTE));
		res.add(createMetaMessOnEvent(note+10, tick+delay, Exo.DESACTIVATENOTE));
		res.add(createNoteOffEvent(note, tick+delay));
		res.add(createNoteOffEvent(note+4, tick+delay));
		res.add(createNoteOffEvent(note+7, tick+delay));
		res.add(createNoteOffEvent(note+10, tick+delay));
		*/
		
		if (note%12>4){
			res.add(createNoteOnEvent(note-2, tick));
			res.add(createMetaMessOnEvent(note-2, tick, Exo.ACTIVATENOTE));
			res.add(createMetaMessOnEvent(note-2, tick+delay, Exo.DESACTIVATENOTE));
			res.add(createNoteOnEvent(note+2, tick));
			res.add(createMetaMessOnEvent(note+2, tick, Exo.ACTIVATENOTE));
			res.add(createMetaMessOnEvent(note+2, tick+delay, Exo.DESACTIVATENOTE));
			res.add(createNoteOnEvent(note+4, tick));
			res.add(createMetaMessOnEvent(note+4, tick, Exo.ACTIVATENOTE));
			res.add(createMetaMessOnEvent(note+4, tick+delay, Exo.DESACTIVATENOTE));
			res.add(createNoteOnEvent(note+9, tick));
			res.add(createMetaMessOnEvent(note+9, tick, Exo.ACTIVATENOTE));
			res.add(createMetaMessOnEvent(note+9, tick+delay, Exo.DESACTIVATENOTE));
			res.add(createNoteOffEvent(note-2, tick+delay));
			res.add(createNoteOffEvent(note+2, tick+delay));
			res.add(createNoteOffEvent(note+4, tick+delay));
			res.add(createNoteOffEvent(note+9, tick+delay));
		}
		else {
			res.add(createNoteOnEvent(note+4, tick));
			res.add(createMetaMessOnEvent(note+4, tick, Exo.ACTIVATENOTE));
			res.add(createMetaMessOnEvent(note+4, tick+delay, Exo.DESACTIVATENOTE));
			res.add(createNoteOnEvent(note+9, tick));
			res.add(createMetaMessOnEvent(note+9, tick, Exo.ACTIVATENOTE));
			res.add(createMetaMessOnEvent(note+9, tick+delay, Exo.DESACTIVATENOTE));
			res.add(createNoteOnEvent(note+10, tick));
			res.add(createMetaMessOnEvent(note+10, tick, Exo.ACTIVATENOTE));
			res.add(createMetaMessOnEvent(note+10, tick+delay, Exo.DESACTIVATENOTE));
			res.add(createNoteOnEvent(note+14, tick));
			res.add(createMetaMessOnEvent(note+14, tick, Exo.ACTIVATENOTE));
			res.add(createMetaMessOnEvent(note+14, tick+delay, Exo.DESACTIVATENOTE));
			res.add(createNoteOffEvent(note+4, tick+delay));
			res.add(createNoteOffEvent(note+9, tick+delay));
			res.add(createNoteOffEvent(note+10, tick+delay));
			res.add(createNoteOffEvent(note+14, tick+delay));
		}

		
		
		return res;
	}

	@Override
	public String chordName() {
		// TODO Auto-generated method stub
		return NoteGenerator.getNoteName(this.tonique)+ "7";
	}

}
